<?php

class User_Customize {
    const USER_INFO = "mod_customize";
    const GROUP = "default";


    public static function create($data){
        list($insert_id, $rows) = DB::insert(self::USER_INFO)
            ->columns (array_keys($data))
            ->values (array_values($data))
            ->execute(self::GROUP);
        return $insert_id;
    }

    public static function update($data,$key,$value){
        $rows = DB::update(self::USER_INFO)
            ->set($data)
            ->where($key, '=', $value)
            ->execute(self::GROUP);
        return $rows;
    }

    public static function getCustomizeData($status=-1,$limit=20,$offset=0){
        $query = $query_counts = DB::select()
            ->from(self::USER_INFO);

        if($status != -1){
            $query = $query_counts = $query->where('status','=',$status);
        }

        $counts = $query_counts ->execute()->count();

        $query =  $query->limit($limit)
            ->offset($offset)
            ->order_by('created','desc')->execute()->as_array();
//        var_dump($query,$counts);
        return array($counts,$query);
    }

}